package com.example.skytakeoutserver.data.response

import com.example.serverbase.constant.MessageConst.ACTION_SUCCESS
import io.swagger.v3.oas.annotations.media.Schema
import lombok.Getter
import lombok.Setter

@Setter
@Getter
@Schema(title = "接口响应")
data class ApiResponse<T>(
    val code: Int,
    val msg: String?,
    val data: T?
) {
    companion object {
        fun <T> success(): ApiResponse<T> = ApiResponse(
            code = 1,
            msg = ACTION_SUCCESS,
            data = null
        )

        fun <T> success(data: T): ApiResponse<T> = ApiResponse(
            code = 1,
            msg = ACTION_SUCCESS,
            data = data
        )

        fun <T> error(msg: String): ApiResponse<T> = ApiResponse(
            code = 0,
            msg = msg,
            data = null
        )
    }
}